package com.example.wnn.web;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.example.wnn.utils.ExcelUtil;
import com.example.wnn.web.vo.Pson;

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.*;

public class ExcelTest {

    private static final List<String> testTitle = Arrays.asList("id","姓名","年龄","手机号码");
    private static final List<String> zdList = Arrays.asList("id","name","age","phone");


    public static void main(String[] args) throws IOException {

        List<Map<String,Object>> list = new ArrayList<>();
        List<Pson> psons = new ArrayList<>();
        for (int i = 1; i < 10; i++) {
         /*   Map<String,Object> map = new HashMap<>();
            map.put("id",i);
            map.put("name","姓名"+i);
            map.put("age","年龄"+i);
            map.put("phone","sj"+i);*/
            Pson  pson = new Pson();
            pson.setId(i+"");
            pson.setName("姓名"+i);
            pson.setAge(1+i);
            pson.setPhone("sj"+i);
            psons.add(pson);
        }

        Field[] fields = Pson.class.getDeclaredFields();
        List<String> baseHead=new ArrayList<>();
        for (Field field : fields) {
            baseHead.add(field.getName());
        }

        for (Pson pson : psons) {
          list.add(JSONUtil.toBean((JSONObject) JSONUtil.parse(pson),Map.class))  ;
      }

        System.out.println(list);

        ExcelUtil.createExcel("/Users/wenzheng/Desktop/task/excel","你好",testTitle,zdList,list);
    }
}
